package com.example.demo.suanfa_jiegou;

/**
 * @program: java_base
 * @description: 删除所有值，单链表
 * @author: zhouhongtao
 * @happyCreateTime: 2022/02/09 17:42
 */
public class DeleteValueSingleLinked {


    public Node deleteValues(Node head, int value) {
        Node retHead = head;
        while (retHead !=null){
            if ((int)retHead.value == value){
                // 没有摘除前一个引用
                head = head.next;
            }
        }
        return retHead;
    }




    /**
     *     单链表
     */
    class Node<T>{
        public T value ;
        private Node next;
        private Node(T value){
            this.value = value;
        }
        private Node(T value, Node next){
            this.value = value;
            this.next = next;
        }

        @Override
        public String toString() {
            return "SingleNode{" +
                    "value=" + value +
                    ", next=" + next +
                    '}';
        }
    }
}
